package com.ecb.business.controller;

import com.ecb.business.dto.api.ApiResult;
import com.ecb.business.dto.chain.HealthCheckDTO;
import com.ecb.business.dto.contract.ExecContractDTO;
import com.ecb.business.dto.contract.QueryContractDTO;
import com.ecb.business.service.ContractService;
import com.ecb.business.service.HealthCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("openApi")
public class OpenApiController {

    @Autowired
    HealthCheckService healthCheckService;
    @Autowired
    ContractService contractService;

    @GetMapping("healthCheck")
    public ApiResult healthCheck(@RequestBody HealthCheckDTO healthCheckDTO){
        return ApiResult.T(healthCheckService.doHealthCheck(healthCheckDTO));
    }

    @GetMapping("getChainConfig")
    public ApiResult getChainConfig(){
        return ApiResult.T(contractService.getChainConfig());
    }

    @PostMapping("queryContract") // 查询类型的合约，结果不会上链
    public ApiResult queryContract(@RequestBody QueryContractDTO queryContractDTO ){
        return ApiResult.T(contractService.queryContract(queryContractDTO));
    }

    @PostMapping("execContract") // 执行类型的合约，结果会上链
    public ApiResult execContract(@RequestBody ExecContractDTO execContractDTO ){
        return ApiResult.T(contractService.execContract(execContractDTO));
    }
}
